package com.threadStudy;

import java.awt.image.renderable.RenderableImageProducer;

/**
 * Created by shaxj on 16/6/16.
 */
public class DeadLockDemo {
    private static String A = "A";
    private static String B = "B";

    public static void main(String args[]) {

        new DeadLockDemo().deadLock();

    }

    private void deadLock() {
         final Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (A) {

                    try {
                        Thread.currentThread().sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    synchronized (B) {
                        System.out.println("1");
                    }

                }
            }
        });

        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("进入t2 B 前");
                synchronized (B){
                    System.out.println("进入t2 B 后");
                    synchronized (A){
                        System.out.println("进入t2 A 后");
                        System.out.println("2");
                    }

                }
            }
        });

        t1.start();
        t2.start();

    }


}
